﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SQLite;

namespace AFT2
{
    [Serializable]
    public class SMSDataObject
    {
        public SMSDataObject(string phoneNumber, string read, string date, string locked, string type, string body)
        {
            PhoneNumber = phoneNumber;
            Read = read;
            Date = date;
            Locked = locked;
            Type = type;
            Body = body;
        }
        public string PhoneNumber { get; set; }
        public string Read { get; set; }
        public string Date { get; set; }
        public string Locked { get; set; }
        public string Type { get; set; }
        public string Body { get; set; }

    }
    [Serializable]
    public class SMSDataList
    {
        public List<SMSDataObject> data;
        public SMSDataList()
        {
            this.data = new List<SMSDataObject>();

            SQLiteConnection myConnection = new SQLiteConnection();
            myConnection.ConnectionString = "Data Source=db\\phoneData.db";
            myConnection.Open();
            SQLiteCommand sqlcmd = new SQLiteCommand(myConnection);
            sqlcmd.CommandText = "select * from sms;";
            SQLiteDataReader reader = sqlcmd.ExecuteReader();
            while (reader.Read())
            {
                this.data.Add(
                    new SMSDataObject(
                        "" + reader["number"],
                        "" + reader["read"],
                        "" + reader["date"],
                        "" + reader["locked"],
                        "" + reader["type"],
                        "" + reader["body"])
                    );
            }

            reader.Close();
            myConnection.Close();
        }
    }
}
